<?php namespace Admin\Controller;
class LinkController extends  CommonController{
	protected $db;
	public function __construct(){
		$this->db=new  \Common\Model\Link;
	}
	
	public function index(){
		//获得所有数据
		$olddata = $this->db->get();
	     View::with("olddata",$olddata);
		 View::make();
	}
	/*
	 * 添加友情链接
	 * */
	public function add(){
		if(IS_POST){

		  if(!$this->db->store()){
//			添加失败
			View::error($this->db->getError());
			}else{
//			添加成功
			View::success("添加成功",U("Link/index"));
		 }
	  } 
		View::make();
	}
	/*
	 * 编辑
	 * */
	public function edit(){
		$lid = 	Q("get.lid",0,"intval");
		//获取旧数据
		$olddata = $this->db->where("lid",$lid)->first();
        View::with("olddata",$olddata);
		if(IS_POST){
		  if(!$this->db->edit()){
			//添加失败
			View::error($this->db->getError());
			
		  }else{
			//添加成功
			View::success("编辑成功",U("Link/index"));
		 }
	  } 
		
		View::make(); 
	}
	/*
	 * 删除
	 * */
	public function del(){
		$lid = Q("get.lid",0,"intval");
		$this->db->where("lid",$lid)->delete();
		View::success("删除成功",U("index"));
		
	}
}
